// 配置 Mock 路径
require.config({
    // baseUrl : "js",
    // shim: {
    //     "underscore": {
    //         exports: "_";
    //     }
    // },
    // shim: {
    //     "underscore": {
    //         exports: "_";
    //     },
    //     "jquery.form": {
    //         deps: ["jquery"]
    //     }
    // },
    // 可以简写成
    // shim: {
    //     "underscore" : {
    //         exports : "_";
    //     },
    //     "jquery.form" : ["jquery"]
    // },
    paths: {
        mock: 'http://mockjs.com/dist/mock',
        jquery: ['http://cdn.bootcss.com/jquery/1.10.2/jquery.min', '../../js/jquery.min']
    }
})

// 加载 Mock
require(['mock', 'jquery'], function(Mock, $) {
    // Mock.mock( template )
    // var data = Mock.mock({
    //     'list|1-10': [{
    //         'id|+1': 1
    //     }]
    // });
    var data = Mock.mock({
        'string1|2': 'i love u ',
        'number1|+2': 1,
        'number2|1-100': 99,
        'number3|1-100.2': 99,
        'number4|1-100.2-4': 99,
        'uLoveMe|1': true,
        'iLoveU|1-9': false, // 为false的概率是1/(1+9),为true的概率是9/(1+9)
        'personInfo|2': {
            name: 'Maria',
            age: 20,
            sex: 'woman',
            profession: 'professor',
            address: '上海'
        },
        'personInfo1|3-6': {
            name: 'Maria',
            age: 20,
            sex: 'woman',
            profession: 'engineer',
            address: '上海',
            phone: '123',
            favorite: 'food',
            hobby: 'travel',
            journey: 'Beijing meeting'
        },
        'nameArr|2': ['Maria', 'Jack', 'Tom', 'Willion'],
        'nameArr1|1': ['Maria', 'Jack', 'Tom', 'Willion'],
        'nameArr2|+1': ['Maria', 'Jack', 'Tom', 'Willion'],
        'nameArr2|2-4': ['Maria', 'Jack', 'Tom', 'Willion', 'Alina', 'Dawn', 'Ellen', 'Lucy', 'Phoebe', 'Thea'],
        'fun1': function() {
            return Math.random();
        },
        'regexp1': /[a-z][A-Z][0-9]/,
        'regexp2': /\w\W\s\S\d\D/,
        'regexp3': /\d{5,10}/,
        placeholder: {
            first: '@FIRST',
            middle: '@FIRST',
            last: '@LAST',
            full: '@first @middle @last'
        }
    });
    $('<pre>').text(JSON.stringify(data, null, 4))
        .appendTo('body')

    // Mock.mock(rurl, template)
    Mock.mock(/\.json/, {
        'list|1-10': [{
            'id|+1': 1,
            'email': '@EMAIL',
            'regexp3': /\d{5,10}/
        }]
    })
    $.ajax({
        url: 'hello.json',
        dataType: 'json'
    }).done(function(data, status, jqXHR) {
        $('<pre>').text(JSON.stringify(data, null, 4))
            .appendTo('body')
    })
})